
/*!
 * \file      container.cpp
 * \brief     Container implementation.
 * \author    Duriez Franck
 * \version   0.5
 */

#include <pthread.h>

template < class Obj, class Coord >
Container<Obj, Coord>::Container(int size) throw(std::length_error) /*{{{*/
{
	// Container::m_objects initialization
	std::vector<Obj*> aux(size, (Obj*)NULL);
	aux.reserve(size);
	m_objects = aux;
} /*}}}*/

template < class Obj, class Coord >
Container<Obj, Coord>::~Container() /*{{{*/
{
	typename std::vector<Obj*>::const_iterator it;

	for (it = m_objects.begin(); it < m_objects.end(); it++)
	{
	    if (*it) delete (*it);
	}
} /*}}}*/

template < class Obj, class Coord >
void Container<Obj, Coord>::forAllObjects(void (Obj::*process)()) const /*{{{*/
{
	// object iterator
	typename std::vector<Obj*>::const_iterator it;

	// object process
	for (it = m_objects.begin(); it < m_objects.end(); it++)
	{
	    if (*it) ((*it)->*process)();
	}
} /*}}}*/

template < class Obj, class Coord >
void Container<Obj, Coord>::forAllObjects(void(Obj::*process)() const) const /*{{{*/
{
	typename std::vector<Obj*>::const_iterator it;

	for (it = m_objects.begin(); it < m_objects.end(); it++)
	{
	    if (*it) ((*it)->*process)();
	}
} /*}}}*/

